<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h1>{{this.$store.state.num}}</h1>
        <button @click="add">加1</button>
    </div>
</body>
<script src="./node_modules/vue/dist/vue.js"></script>
<script src="./node_modules/vuex/dist/vuex.js"></script>
<script>
    console.log(Vuex);
    //a,2 新建一个仓库

    let store = new Vuex.Store({
        //定义状态
        state:{
            num:888,
        },
        //定义操作数据
        mutations:{
            //加1
            increment:function(state){
                state.num++;
            },
        },
    });
    //a,3 把store 作为配置项,传到Vue实例中
    let vm = new Vue({
        store, //this.$etore => store
        el:"#app",
        data:{
            num:store.state.num //888
        },
        methods:{
            add:function(){
                this.$store.commit("increment")
            }
        }
    })
</script>
</html>